package com.xbang.attendance.web.action.purchase.companygps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo2do.lighturl.annotation.Action;

import com.xbang.attendance.entity.companygps.companyGps;
import com.xbang.attendance.entity.companygps.scope;
import com.xbang.attendance.service.SystemService;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.SearchActionSupport;

public class Index extends SearchActionSupport {

	private SystemService systemService;
	private companyGps user;
	

	public companyGps getUser() {
		return user;
	}

	public void setUser(companyGps user) {
		this.user = user;
	}
	private List<companyGps> companyGpses = new ArrayList<companyGps>();

	

	public List<companyGps> getCompanyGpses() {
		return companyGpses;
	}

	public void setCompanyGpses(List<companyGps> companyGpses) {
		this.companyGpses = companyGpses;
	}

	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub

	}
	private List mapDepartmentlist=new ArrayList();
	

	public List getMapDepartmentlist() {
		return mapDepartmentlist;
	}

	public void setMapDepartmentlist(List mapDepartmentlist) {
		this.mapDepartmentlist = mapDepartmentlist;
	}

	@Action("/purchase/companygps/list")
	public String list() throws Exception {
		String hqlSentence = "FROM companyGps companyGps WHERE 1 = 1";
		Result result = systemService.searchByPage(hqlSentence,
				searchComponent, page);
		companyGpses = result.getItems();
		for(int i=0;i<companyGpses.size();i++){
			String j = "0";
			companyGpses.get(i).getScope();

			int deid= -1;
			
			
				try {
					Map mapDepartment=new HashMap();
					if(companyGpses.get(i).getScope()==null||"".equals(companyGpses.get(i).getScope())){
						mapDepartment.put("scope", null);
					}else{
						deid	=Integer.valueOf(companyGpses.get(i).getScope());
						scope dp=(scope) systemService.getObject(scope.class, deid);
						if(dp!=null){
							mapDepartment.put("scope", dp.getScopename());
						}
							
					}
					
					companyGps userinfo=new companyGps();
					userinfo=companyGpses.get(i);
					mapDepartment.put("uinfo", userinfo);
					mapDepartmentlist.add(mapDepartment);
				} catch (Exception e) {
					e.printStackTrace();
				}
			
		}
		
		page = result.getPage();
		return "index";
	}
}
